package com.itheima.mp.controller;


import com.itheima.mp.domain.po.UserInfoAuto;
import com.itheima.mp.domain.po.Uuser;
import com.itheima.mp.service.IUserInfoAutoService;
import com.itheima.mp.service.IUuserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-12-10
 */
@RestController
@RequestMapping("/uuser")
public class UuserController {
    @Autowired
    private IUuserService UuserServiceImpl;

    // 增加用户 - 仅限POST请求
    @PostMapping("/add")
    public boolean addUser(@RequestBody Uuser userInfoAuto) {
        return UuserServiceImpl.save(userInfoAuto);
    }

    // 根据ID查询用户 - 仅限GET请求
    @GetMapping("/{id}")
    public Uuser getUserById(@PathVariable Integer id) {
        return UuserServiceImpl.getById(id);
    }

    // 查询所有用户 - 仅限GET请求
    @GetMapping("/all")
    public List<Uuser> getAllUsers() {
        return UuserServiceImpl.list();
    }

    // 更新用户信息 - 仅限PUT请求
    @PutMapping("/update")
    public boolean updateUser(@RequestBody Uuser userInfoAuto) {
        return UuserServiceImpl.updateById(userInfoAuto);
    }

    // 根据ID删除用户 - 仅限DELETE请求
    @DeleteMapping("/{id}")
    public boolean deleteUser(@PathVariable Integer id) {
        return UuserServiceImpl.removeById(id);
    }

}
